package com.globallogic.vkulyk.SSHTool;

import static org.junit.Assert.*;
import org.junit.*;

import com.jcraft.jsch.Session;
import java.io.File;

public class Unit_FileGetter extends SSHToolTester {
	private static final String FILE_IS_NOT_FOUND_LOCALLY = "File is not found locally";
	private String dstFile = "";

	@Before
	public void setup() {
		setVarsFromPropertiesFile("testData/testing.properties");
		String fileName = new File(srcFileForGet).getName();
		dstFile = dstDirForGet + "/" + fileName;
		new File(dstFile).delete();
	}

	@Test
	public void shouldGetFile_whenCallExecute() {
		// when
		new FileGetter(host, port, user, password, srcFileForGet, dstDirForGet)
				.execute();

		// then
		assertTrue(FILE_IS_NOT_FOUND_LOCALLY, new File(dstFile).exists());
	}

	@Test
	public void shouldGetFile_whenCallExecuteInExistingSession() {
		// given
		ActionExecutor actionExecutor = new ActionExecutor(host, port, user,
				password);
		Session session = actionExecutor.openSession();

		// when
		new FileGetter(host, port, user, password, srcFileForGet, dstDirForGet)
				.executeInExistingSession(session);

		// then
		assertTrue(FILE_IS_NOT_FOUND_LOCALLY, new File(dstFile).exists());
		actionExecutor.closeSession(session);
	}
}
